package pe.com.cotelasa.seguridad.entidad;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
 
@Entity
@Table(name = "menu",catalog = "bdcotelasa", schema = "seguridad")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Menu.findAll", query = "SELECT m FROM Menu m"),
    @NamedQuery(name = "Menu.findById", query = "SELECT m FROM Menu m WHERE m.id = :id"),
    @NamedQuery(name = "Menu.findByNombre", query = "SELECT m FROM Menu m WHERE m.nombre = :nombre"),
    @NamedQuery(name = "Menu.findByDescripcion", query = "SELECT m FROM Menu m WHERE m.descripcion = :descripcion"),
    @NamedQuery(name = "Menu.findByAccion", query = "SELECT m FROM Menu m WHERE m.accion = :accion"),
    @NamedQuery(name = "Menu.findByEstadoRegistro", query = "SELECT m FROM Menu m WHERE m.estadoRegistro = :estadoRegistro")})
public class Menu implements Serializable {
 
	private static final long serialVersionUID = 471450194423871778L;

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    
    @Basic(optional = false)
    @Column(name = "descripcion")
    private String descripcion;
    
    @Column(name = "accion")
    private String accion;
    
    @Basic(optional = false)
    @Column(name = "estado_registro")
    private char estadoRegistro;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "menu",fetch=FetchType.LAZY)
    private Collection<MenuRol> menuRolCollection;
    
    @OneToMany(mappedBy = "idMenuPadre",fetch=FetchType.LAZY)
    private Collection<Menu> menuCollection;
    
    @JoinColumn(name = "id_menu_padre", referencedColumnName = "id")
    @ManyToOne(fetch=FetchType.LAZY)
    private Menu idMenuPadre;

    public Menu() {
    }

    public Menu(Integer id) {
        this.id = id;
    }

    public Menu(Integer id, String nombre, String descripcion, char estadoRegistro) {
        this.id = id;
        this.nombre = nombre;
        this.descripcion = descripcion;
        this.estadoRegistro = estadoRegistro;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public String getAccion() {
        return accion;
    }

    public void setAccion(String accion) {
        this.accion = accion;
    }

    public char getEstadoRegistro() {
        return estadoRegistro;
    }

    public void setEstadoRegistro(char estadoRegistro) {
        this.estadoRegistro = estadoRegistro;
    }

    @XmlTransient
    public Collection<MenuRol> getMenuRolCollection() {
        return menuRolCollection;
    }

    public void setMenuRolCollection(Collection<MenuRol> menuRolCollection) {
        this.menuRolCollection = menuRolCollection;
    }

    @XmlTransient
    public Collection<Menu> getMenuCollection() {
        return menuCollection;
    }

    public void setMenuCollection(Collection<Menu> menuCollection) {
        this.menuCollection = menuCollection;
    }

    public Menu getIdMenuPadre() {
        return idMenuPadre;
    }

    public void setIdMenuPadre(Menu idMenuPadre) {
        this.idMenuPadre = idMenuPadre;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Menu)) {
            return false;
        }
        Menu other = (Menu) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.com.cotelasa.seguridad.entidad.Menu[ id=" + id + " ]";
    }
    
}
